<?php
	class userControl extends Control{
	
		function reg_show(){
			  C("debug", 0);
			$web=__WEB__;
			$this->assign("web",$web);
			$this->display();
		}
		function reg(){
			/* $_POST['password']=md5($_POST['password']);
			$db = M("user");
			$username = $_POST['username'];
			if(empty($_POST['password']) || empty($username)){
			$this->error('请正确填写用户或密码');
			}
			$row = $db->where("username='{$username}'")->select();
			if($db->affected_rows){
				$this->error('用户已经存在');
			} */
			
			$_POST['password']=md5($_POST['password']);
			//p($_POST);exit;
			$db=K("userrelation");
			$username = $_POST['username'];
			$_POST['username'];
			$row = $db->where("username='$username'")->select();
			if($row){
				$this->error('用户已经存在，请重新填写用户名');
			}else{
				$db->add();
				$this->success("添加用户成功");
			}
		
			
			
			/* if($db->add()){
				$_SESSION['uid']=$db->insert_id;
				$_SESSION['username'] = $_POST['username'];
				$this->success("注册成功","login_show");
			}else{
				$this->error("请正确填写用户或密码");
			} */
		}
		function out(){
			$_SESSION=array();
			session_destroy();
			$this->success("您已经成功退出",__WEB__);
		}
		function login_show(){
		  C("debug", 0);
			$web=__WEB__;
			$this->assign("web",$web);
			$this->display(); 
		}
		function login(){
			$username=$_POST['username'];
			$pwd=md5($_POST['password']);
				//print_r($username);
				//print_r($pwd);
			$db= M("user");
			$row = $db->where("username='{$username}'")->select();
		    //var_dump($row);
			foreach($row as $v){
				$p=$v["password"];
				$uid=$v["uid"];
				$user1=$v["username"];
			}
			if(@$p==$pwd && $username==@$user1 && !$username==""){
				$_SESSION['uid']=$uid;
				$_SESSION['username'] = $username;
				
			$this->success("登录成功成功",__WEB__);
			}else{
				$this->error("用户名或密码错误");
			}
		}
	}
?>